package com.cilico.single.components;

import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.graphics.drawable.shapes.RoundRectShape;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.cilico.single.ConfigManager;
import com.cilico.single.R;
import com.cilico.single.components.Table.Cell.CellLayout;
import com.cilico.single.utils.ConstantRepository;
import com.cilico.single.utils.Utils;
import com.cilico.single.view.BaseView;
import com.cilico.single.view.DetailView;
import com.cilico.single.view.FormLayout;
import com.cilico.single.view.LPLinearLayoutView;

public class Table extends RelativeLayout implements Panel {

	FormLayout formLayout_;
	public CssStyle cssStyle_;
	public String attrName_;
	public String form;
	String updateUrl_;// 局部更新table的链接
	String updateTime_;// 更新间隔时间
	public static Timer tableTimer_ = null;

	// 1 row/col above + 1 row/col below + 1 row/col for separator
	static final int OFFSET = 0;

	// The max width of each column.
	private int[] maxWidthCol_;
	// The max Height of each row.
	private int[] maxHeightRow_;

	private static Table thisTable_;
	// 保存触摸按下时的X坐标
	int downX_;
	int downY_;
	int tScrollX_;
	int tScrollY_;
	int laytHeight_;
	// Store the cell's text of the table, in each cell of the table contents multi components.
	public Vector<Cell> cells_;

	private int cols_;
	private int rows_;

	// 标志是否是更新当前table，所有table公用
	public static int isUpdateTable_ = -1;

	// True if this table has a border.
	public boolean hasBorder_ = true;
	public boolean hasTextField_;
	public boolean isfull_;
	public int width_;
	public int height_;

	int textColor_; // normal text color.

	private Paint tablePaint_;
	ComponentListener listener_;
	BaseView bv_;

	// store the addendum of each <tr>.
	ArrayList<String> addendum_;
	// store the accessory of each <tr>.
	ArrayList<String> accessory_;
	
	// store the current accessory
	int currentAccessoryIndex_;

	private ShapeDrawable drawable_;
	private static final int PADDING_HORIZONAL = 0;
	private static final int PADDING_VERTICAL = 0;
	private static final int CORNER_RADIUS = 5;
	private static Bitmap TABLEARR = null;
	private static Bitmap TABLEARR_1 = null;
	private static Bitmap TABLEARR_2 = null;
	private static Bitmap TABLEARR_3 = null;
	private static int TABLE_ARR_HORIZONAL_MARGIN = 5;

	private static final int MAX_WIDTH = Utils.screenWidth_ - 5 * 2
			- PADDING_HORIZONAL * 2 - BaseView.SCROLL_BAR_AREA_WIDTH;

	private static final int INNER_BORDER_COLOR = 0xffe1e1e1;

	private Bitmap backgroundImg_;

	private ArrayList<CssStyle> rowStyle;

	// indicator on drawing background of current touched row.
	private boolean isDrawRowBg_;
	// background color of current touched row.
	private static final int ROW_TOUCH_BG_COLOR = 0xff2762e1;

	private LPLinearLayoutView linearLayoutView_;

	private static final int DEFAULT_CELL_HEIGHT = 40;
	private static final int DEFAULT_CELL_PADDING_HORIZONAL = 5;
	private static final int DEFAULT_CELL_PADDING_VERTICAL = 2;

	public static int firstColWidth_ = 0;
	static boolean iscontain_;

	Cell currentCell_;
	private long systemTime_ = 0;

	/**
	 * @author Chris
	 * 
	 */
	public static class Cell implements Component {
		private CellLayout cellLayout_;
		public ArrayList<Component> cellItems;
		int c = -1; // The col index of this cell.
		int r = -1; // The row index of this cell.
		int cSpan = 1; // The c number of this cell span.
		int rSpan = 1; // The r number of this cell span.
		int bgColor = 0;
		private int width_;
		private int height_;
		protected CssStyle cssStyle_;

		/**
		 * @author Chris
		 * 
		 */
		public class CellLayout extends LinearLayout implements Component {

			private final Table table_;
			private final Cell cell_;

			private int touchDownX_;
			private int touchDownY_;
			private int scrollX_;
			boolean isMove_;

			private long systemTime_ = 0;

			public CellLayout(Table table, Table.Cell cell) {
				super(table.bv_);
				table_ = table;
				thisTable_ = table;
				cell_ = cell;
				setFocusable(false);
				setGravity(Gravity.CENTER_VERTICAL);
			}

			public void addView(View child) {
				try {
					Component c = (Component) child;
					c.mould();
					super.addView(c.getCmpView());
				} catch (Exception e) {
					// TODO Auto-generated catch block
					Utils.printException(e);
				}
			}

			public boolean onTouchEvent(MotionEvent event) {
				int touchEvent = event.getAction();
				int x = (int) event.getX();
				int y = (int) event.getY();

				try {
					switch (touchEvent) {
					case MotionEvent.ACTION_DOWN:
						systemTime_ = System.currentTimeMillis() - systemTime_;
						touchDownX_ = (int) event.getX();
						scrollX_ = table_.getScrollX();
						touchDownY_ = (int) event.getY();
						table_.setCurrentTouchRow(cell_);
						table_.isDrawRowBg_ = true;
						isMove_ = false;
						table_.invalidate();
						// layoutHeight_ = (table_.getLayoutParams()).height;
						if (table_.linearLayoutView_ != null) {
							DetailView.scrollView_ = table_.linearLayoutView_;
							table_.linearLayoutView_.scrollY_ = table_.linearLayoutView_
									.getScrollY();
						}
						break;
					case MotionEvent.ACTION_UP:
						table_.setCurrentTouchRow(cell_);
						if (!isMove_ && systemTime_ > 1000) {
							table_.tablePressed();
						}
						table_.isDrawRowBg_ = false;
						table_.invalidate();
						break;
					case MotionEvent.ACTION_MOVE:
						if (Math.abs(x - touchDownX_) > 5
								|| Math.abs(y - touchDownY_) > 5) {
							// 不响应弹起操作
							isMove_ = true;
							if (table_.width_ > Utils.screenWidth_) {
								// 修正用于移动table的触摸x坐标
								x += scrollX_ - table_.getScrollX();
								if ((x - touchDownX_) > 0) {

									// 向右拖動
									int move = (x - touchDownX_) > scrollX_ ? 0
											: (scrollX_ - x + touchDownX_);
									table_.scrollTo(move, 0);
								} else {
									// 向左拖動
									int move = 0;
									if (table_.width_ > Utils.screenWidth_
											+ scrollX_
											- BaseView.DEFAULT_VIEW_TOP_MARGIN) {

										move = (touchDownX_ - x) > (table_.width_
												- Utils.screenWidth_
												- scrollX_ + BaseView.DEFAULT_VIEW_TOP_MARGIN) ? (table_.width_
												- Utils.screenWidth_ + BaseView.DEFAULT_VIEW_TOP_MARGIN)
												: (touchDownX_ - x + scrollX_);
										table_.scrollTo(move, 0);
									}
								}
							}

							// if (table_.height_ > layoutHeight_) {
							// // 修正用于移动table的触摸y坐标
							// y += scrollY_ - table_.getScrollY();
							// if ((y - touchDownY_) > 0) {
							// // 向下拖動
							// int move = (y - touchDownY_) > scrollY_ ? 0
							// : (scrollY_ - y + touchDownY_);
							// table_.scrollTo(0, move);
							// } else {
							// // 向上拖動
							// int move = 0;
							//
							// if (table_.height_ > layoutHeight_
							// + scrollY_) {
							// move = (touchDownY_ - y) > (table_.height_
							// - layoutHeight_ - scrollY_) ? (table_.height_
							// - layoutHeight_ + 5)
							// : (touchDownY_ - y + scrollY_);
							// table_.scrollTo(0, move);
							// }
							// }
							// }
						}
						table_.isDrawRowBg_ = false;
						break;
					default:
						table_.isDrawRowBg_ = false;
						return super.onTouchEvent(event);
					}

				} catch (Exception e) {
					// TODO Auto-generated catch block
					Utils.printException(e);
				}
				return false;
			}

			public void cleanText() {
				// TODO Auto-generated method stub

			}

			public String getContentText() {
				// TODO Auto-generated method stub
				return null;
			}

			public CssStyle getCssStyle() {
				// TODO Auto-generated method stub
				return null;
			}

			public int getCmpHeight() {
				// TODO Auto-generated method stub
				return 0;
			}

			public View getCmpView() {
				// TODO Auto-generated method stub
				return null;
			}

			public int getCmpWidth() {
				// TODO Auto-generated method stub
				return 0;
			}

			public boolean isInTable() {
				// TODO Auto-generated method stub
				return false;
			}

			public void mould() {
				// TODO Auto-generated method stub

			}

			public void releaseResource(View view) {
				// TODO Auto-generated method stub
				Utils.releaseResource(view);
				if (thisTable_ != null) {
					// thisTable_.removeAllViews();
					thisTable_ = null;
				}
			}

			public void setContentText(String text) {
				// TODO Auto-generated method stub

			}

			public void setCssStyle(CssStyle style) {
				// TODO Auto-generated method stub

			}

			public void setInTable(boolean inTable) {
				// TODO Auto-generated method stub

			}

			public void setCmpHeidht(int height) {
				// TODO Auto-generated method stub

			}

			public void setCmpWidth(int width) {
				// TODO Auto-generated method stub

			}

			public void shrinkWidth() {
				// TODO Auto-generated method stub

			}

			public void setForm(FormLayout formLayout) {
				// TODO Auto-generated method stub

			}

			public FormLayout getForm() {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public void setEncrypt(String encrypt) {
				// TODO Auto-generated method stub

			}

		}

		/**
         * 
         */
		public Cell() {
			cellItems = new ArrayList<Component>();
		}

		/**
		 * @param table
		 * @param width
		 * @param height
		 */
		private void createLayout(Table table) {
			cellLayout_ = new CellLayout(table, this);
			cellLayout_.setPadding(DEFAULT_CELL_PADDING_HORIZONAL,
					DEFAULT_CELL_PADDING_VERTICAL,
					DEFAULT_CELL_PADDING_HORIZONAL,
					DEFAULT_CELL_PADDING_VERTICAL);
			cellLayout_.setOrientation(LinearLayout.VERTICAL);
			cellLayout_.setBackgroundColor(bgColor);
			cellLayout_.setGravity(Gravity.CENTER_VERTICAL);
		}

		/**
		 * @return
		 */
		public int size() {
			if (cellItems != null) {
				return cellItems.size();
			}
			return 0;
		}

		/**
		 * @param index
		 * @return
		 */
		public View elementAt(int index) {
			View v = null;
			try {
				Object o = cellItems.get(index);
				if (o instanceof Wrap)
					return null;
				v = (View) o;
			} catch (Exception e) {
			}
			return v;
		}

		/**
		 * @param view
		 */
		public void add(Component c) {
			c.setInTable(true);
			cellItems.add(c);
		}

		public void cleanText() {
			// TODO Auto-generated method stub

		}

		public String getContentText() {
			// TODO Auto-generated method stub
			return null;
		}

		public void mould() {
			CssStyle cs = cssStyle_;
			if (cs != null && cs.bgColor_ != 0) {
				bgColor = cs.bgColor_;
			}
		}

		public void setContentText(String text) {
			// TODO Auto-generated method stub

		}

		public void setCssStyle(CssStyle style) {
			// TODO Auto-generated method stub

		}

		public void setCmpHeidht(int height) {
			// TODO Auto-generated method stub

		}

		public void setCmpWidth(int width) {
			// TODO Auto-generated method stub

		}

		public void shrinkWidth() {
			// TODO Auto-generated method stub

		}

		public View getCmpView() {
			return cellLayout_;
		}

		public int getCmpHeight() {
			return height_;
		}

		public int getCmpWidth() {
			// TODO Auto-generated method stub
			return 0;
		}

		public void setInTable(boolean inTable) {
			// TODO Auto-generated method stub

		}

		public boolean isInTable() {
			// TODO Auto-generated method stub
			return false;
		}

		public CssStyle getCssStyle() {
			// TODO Auto-generated method stub
			return null;
		}

		public void releaseResource(View view) {
			// TODO Auto-generated method stub
			// cellLayout_ = null;
			// cellItems.clear();
			// cellItems = null;
			// cssStyle_ = null;
			Utils.releaseResource(view);
		}

		public void setForm(FormLayout formLayout) {
			// TODO Auto-generated method stub

		}

		public FormLayout getForm() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public void setEncrypt(String encrypt) {
			// TODO Auto-generated method stub

		}

	}

	/** Creates a new instance of Table */
	public Table(Context context) {
		super(context);
		rows_ = -1;
		cols_ = -1;
		maxWidthCol_ = null;
		maxHeightRow_ = null;
		cells_ = new Vector<Cell>();
		tablePaint_ = new Paint();
		bv_ = (BaseView) this.getContext();
		addendum_ = new ArrayList<String>();
		accessory_ = new ArrayList<String>();
		setPadding(PADDING_HORIZONAL, PADDING_VERTICAL, PADDING_HORIZONAL, PADDING_VERTICAL);
		if (TABLEARR == null) {
			TABLEARR = ConstantRepository.decodeBitmap(context.getResources(), R.drawable.arr);
		}
		if (TABLEARR_1 == null) {
			TABLEARR_1 = ConstantRepository.decodeBitmap(
					context.getResources(), R.drawable.delete);
		}
	}

	/**
	 * @param cell
	 */
	public void addCell(Cell cell) {
		if (cells_ == null) {
			cells_ = new Vector<Cell>();
		}
		cells_.add(cell);
	}

	public void removeAllCells() {
		if (cells_ != null) {
			cells_.removeAllElements();
		}
		removeAllViews();
		reset();
		requestLayout();
	}

	private void reset() {
		rows_ = 0;
		cols_ = 0;
		maxWidthCol_ = null;
		maxHeightRow_ = null;
	}

	/**
	 * Set the fields' value, create cell Views.
	 * 
	 * This method must be invoked after the Table was created and all the
	 * cells were appended.
	 */
	private void reLayoutTable() {
		try {
			// get row and column numbers.
			if (!cells_.isEmpty()) {
				Cell lastCell = cells_.elementAt(cells_.size() - 1);
				rows_ = lastCell.r + lastCell.rSpan;
				cols_ = lastCell.c + lastCell.cSpan;
				lastCell = null;
				maxWidthCol_ = new int[cols_];
				maxHeightRow_ = new int[rows_];
				/* calculate the size of each column and each row. */
				calculateSize();
				/*
				 * create Cell view and set its width and height,and append cell
				 * view to this table.
				 */
				appendCellView();
				/* set table layout parameters for measuring it. */
				setTableLayoutParams();
				/* set table background image. */
				setTableBgImg();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			Utils.printException(e);
		}

	}

	private void resetHeightArray(int OriH, int DesH) {
		// 在通过每行高的数组计算总高的时候加了边距，所以此处要予以相应的减掉
		final int ohTemp = OriH - (PADDING_VERTICAL << 1);
		final int dhTemp = DesH - (PADDING_VERTICAL << 1);
		// 计算缩减系数
		final float temp = (float) (dhTemp) / (float) (ohTemp);
		final int size = maxHeightRow_.length;
		for (int i = 0; i < size; i++) {
			// 根据缩减系数重新计算每行的行高
			maxHeightRow_[i] = (int) (maxHeightRow_[i] * temp);
		}
	}

	/**
     * 
     */
	private void calculateSize() throws Exception {
		int cellsLenght = cells_.size();
		int firstColWidth = 0;
		if ((cellsLenght > 2 && cells_.elementAt(0).r == cells_.elementAt(1).r && cells_
				.elementAt(1).r != cells_.elementAt(2).r)
				|| (cellsLenght == 2 && cells_.elementAt(0).r == cells_
						.elementAt(1).r)) {
			for (int cId = 0; cId < cellsLenght; cId += 2) {
				Cell ccc = cells_.elementAt(cId);
				if (ccc.cellItems.size() > 0) {
					Component c = (Component) ccc.cellItems.get(0);
					c.mould();
					firstColWidth = c.getCmpWidth() > firstColWidth ? c
							.getCmpWidth() : firstColWidth;
					Utils.printOutToConsole("c.getCompWidth = " + firstColWidth);
				}
			}
		}
		for (int cId = 0; cId < cellsLenght; cId++) {
			Cell cell = cells_.elementAt(cId);
			boolean isRightTd = false;
			if (cell == null) {
				continue;
			} else if (cId > 0) {
				Cell ccc = cells_.elementAt(cId - 1);
				if (cell.r != ccc.r) {
					firstColWidth_ = 0;
				} else {
					isRightTd = true;
				}
			}
			int height = 0;
			int width = 0;
			/* create cell layout. */
			cell.createLayout(this);
			if (isRightTd) {
				BaseView.appendChildIntoLayout(bv_, cell.cellLayout_,
						cell.cellItems, firstColWidth);
			} else {
				BaseView.appendChildIntoLayout(bv_, cell.cellLayout_,
						cell.cellItems, 0);
			}
			if (cell.cellItems.size() > 1
					&& cell.cellItems.get(0) instanceof Label) {
				firstColWidth_ = ((Label) cell.cellItems.get(0)).width_;
			}
			for (int i = 0; i < cell.cellLayout_.getChildCount(); i++) {
				View cellItem = cell.cellLayout_.getChildAt(i);
				if (cellItem == null) {
					continue;
				}
				try {
					((Component) cellItem).mould();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					Utils.printException(e);
				}
				ViewGroup.LayoutParams viewLayoutParams = null;
				viewLayoutParams = cellItem.getLayoutParams();
				if (viewLayoutParams == null) {
					continue;
				}
				height += viewLayoutParams.height;
				if (cellItem instanceof mHtmlText) {
					height += 4;
				}
				width = Math.max(width, viewLayoutParams.width);
				/**
				 * ------------------------------------------------------------
				 * 在国航项目的网点查询里面，如果有3个电话并列的时候会出现表格超屏，但是表格无法拖动的情况。估计原因是该处限制了
				 * 宽度，将该处注销，在网点查询里面可以顺利移动表格
				 */
				// if (width > MAX_WIDTH) {
				// width = MAX_WIDTH;
				// }
				/**
				 * ------------------------------------------------------------
				 */

				cellItem = null;
			}
			maxWidthCol_[cell.c] = Math.max(width + 2 * DEFAULT_CELL_PADDING_HORIZONAL, maxWidthCol_[cell.c]);
			maxHeightRow_[cell.r] = Math.max(height + 2 * DEFAULT_CELL_PADDING_VERTICAL, maxHeightRow_[cell.r]);
			maxHeightRow_[cell.r] = Math.max(DEFAULT_CELL_HEIGHT, maxHeightRow_[cell.r]) + 2;
			cell = null;
		}
		firstColWidth_ = 0;
		adjustCellWidth();
		calculateFullWidth();
		calculateHeight();
		lengthenRowPanelWidth();
	}

	/**
	 * Find all the RowPanel in the table and let them fill parent.
	 */
	private void lengthenRowPanelWidth() {
		if (cells_ == null) {
			return;
		}
		int cellSize = cells_.size();
		for (int i = 0; i < cellSize; i++) {
			CellLayout clayout = cells_.elementAt(i).cellLayout_;
			if (clayout == null) {
				continue;
			}
			int itemSize = clayout.getChildCount();
			for (int j = 0; j < itemSize; j++) {
				View v = clayout.getChildAt(j);
				if (v == null) {
					continue;
				}
				if (v instanceof RowPanel) {
					ViewGroup.LayoutParams lp = v.getLayoutParams();
					if (lp != null) {
						lp.width = LayoutParams.FILL_PARENT;
					}
				}
			}
		}

	}

	/**
     * 
     */
	private void adjustCellWidth() {
		// make the last cell wider if the table is hollower than the screen.
		boolean hasNonNull = false;
		for (String s : accessory_) {
			if (s != null) {
				hasNonNull = true;
			}
		}
		int totalWidth = 0;
		for (int w : maxWidthCol_) {
			totalWidth += w;
		}
		int arrowAreaWidth = 0;
		if (hasNonNull) {
			arrowAreaWidth = TABLE_ARR_HORIZONAL_MARGIN * 2
					+ TABLEARR.getWidth();
		}
		int tableWidth = MAX_WIDTH;
		if (cssStyle_ != null && cssStyle_.width_ > 0) {
			tableWidth = cssStyle_.width_;
		}
		int maxWidth = tableWidth - arrowAreaWidth;
		if (totalWidth < maxWidth) {
			maxWidthCol_[cols_ - 1] += maxWidth - totalWidth;
		}
	}

	/**
	 * calculate the full width and height of the table.
	 */
	private void calculateFullWidth() {
		// calculate Full Width
		width_ = OFFSET;// left margin
		for (int i = 0; i < cols_; i++) {
			width_ += maxWidthCol_[i];
		}
		width_ += PADDING_HORIZONAL * 2;
		// Check if there is a non-NULL elements in ArrayList.
		boolean hasNonNull = false;
		for (String s : accessory_) {
			if (s != null) {
				hasNonNull = true;
			}
		}
		if (hasNonNull) {
			width_ += TABLEARR.getWidth() + TABLE_ARR_HORIZONAL_MARGIN * 2;
		}
	}

	/**
     * 
     */
	private void calculateHeight() {
		// calculate Full Height
		height_ = 0;
		for (int i = 0; i < rows_; i++) {
			height_ += maxHeightRow_[i];
		}
		height_ += PADDING_VERTICAL * 2;
		try {
			// int cssHeight = cssStyle_.height_;
			// if (cssHeight > 0) {
			//
			// }
		} catch (Exception e) {
			// TODO Auto-generated catch block
			Utils.printException(e);
		}
	}

	/**
     * 
     */
	private void appendCellView() throws Exception {
		int cellsSize = cells_.size();
		int index = 0;
		Cell cell = null;
		// for (Cell cell : cells_) {
		for (int i = 0; i < cellsSize; i++) {
			index = i;
			cell = cells_.elementAt(index);

			if (cell == null) {
				continue;
			}
			cell.width_ = 0;
			cell.height_ = 0;
			for (int j = cell.c; j < cell.c + cell.cSpan; j++) {
				cell.width_ += maxWidthCol_[j];
			}
			for (int j = cell.r; j < cell.r + cell.rSpan; j++) {
				cell.height_ += maxHeightRow_[j];
			}
			// set id for layout.
			int id = cell.r * cols_ + cell.c + 1;
			cell.cellLayout_.setId(id);
			/* append the cell layout to table. */
			RelativeLayout.LayoutParams lyp = new RelativeLayout.LayoutParams(
					cell.width_, cell.height_);
			if (cell.r == 0) {
				lyp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
			}
			if (cell.c == 0) {
				lyp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
			}
			// get the above cell's id.
			int aboveCellId = cell.cellLayout_.getId() - cols_;
			if (aboveCellId > -1) {
				lyp.addRule(RelativeLayout.BELOW, aboveCellId);
				lyp.addRule(RelativeLayout.ALIGN_LEFT, aboveCellId);
			}
			// get the left cell's id.
			int leftCellId = cell.cellLayout_.getId() - 1;
			if (leftCellId > -1) {
				lyp.addRule(RelativeLayout.RIGHT_OF, leftCellId);
			}
			cell.cellLayout_.setLayoutParams(lyp);
			addView(cell.cellLayout_);
		}
	}

	/**
     * 
     */
	private void setTableLayoutParams() throws Exception {
		BaseView bv = (BaseView) this.getContext();
		// set layout parameters.
		LinearLayout.LayoutParams lop = null;
		int w = width_;
		int h = height_;
		if (cssStyle_ != null && cssStyle_.width_ > 0) {
			w = cssStyle_.width_;
		} else {
			w = MAX_WIDTH;
		}
		if (isfull_) {
			w = Component.MAX_ROW_WIDTH + Utils.getSystemScaledValue(20);
		}
		if (cssStyle_ != null && cssStyle_.height_ > 0) {
			h = cssStyle_.height_;
		}
		lop = new LinearLayout.LayoutParams(w, h);
		if (cssStyle_ != null) {
			/**
			 * 该处暂时修正为不管什么情况设置该表格和上个控件的间距为DEFAULT_VIEW_TOP_MARGIN固定值
			 * 按照，接口定义，该间距应该是根据cssStyle_
			 * .top参数来决定，但是xml中定义的该参数暂时是一个控件间距的绝对值，暂时不适用。 所以此处暂时为写死。
			 */
			if (cssStyle_.top_ == Integer.MIN_VALUE) {
				lop.topMargin = BaseView.DEFAULT_VIEW_TOP_MARGIN;
			} else {
				lop.topMargin = BaseView.DEFAULT_VIEW_TOP_MARGIN;
			}
		}
		// 该判断条件主要是服务于国航项目机票预定的机票列表界面实现定高的处理,list_table名字必须与服务端需要更新的表格节点名一致,
		// 由于服务端没有提供可区别的其他表格标志来将此表格与其它表格区分,所以此处暂时如此.
		if (null != this.attrName_
				&& !this.attrName_.toLowerCase().startsWith("table")
				&& this.attrName_.equalsIgnoreCase("list_table")) {
			// && !this.attrName_.equalsIgnoreCase("head_table")
			// && !this.attrName_.equalsIgnoreCase("cjr_table")
			// && !this.attrName_.equalsIgnoreCase("lxr_table")
			// && !this.attrName_.equalsIgnoreCase("addcjr_table")
			// && !this.attrName_.equalsIgnoreCase("addlxr_table")
			// && !this.attrName_.equalsIgnoreCase("person_table")
			// && !this.attrName_.equalsIgnoreCase("passenger_table")
			// && !this.attrName_.equalsIgnoreCase("pin_table")
			// && !this.attrName_.equalsIgnoreCase("contact_table")
			// && !this.attrName_.equalsIgnoreCase("route_table")
			// && !this.attrName_.equalsIgnoreCase("xz_table")
			// && !this.attrName_.equalsIgnoreCase("mingxi_table")
			// && !this.attrName_.equalsIgnoreCase("edit_table")) {
			// 该判断只是暂时用来判断机票预定里面一个航班列表表格，由于暂时没有一个比较统一的标志来区分这个表格和其他表格，
			// 但是这个表格的高度又只能一定，所以暂时启用此判断条件作判断。
			// 计算该表格可显示的高度值
			Rect frame = new Rect();
			// 1.0的系统参照的是320X480定可见最大高
			// 该高度值已经除去了系统最上方的状态栏高度
			// #ifdef Android1.0
			// @ int heightVisible = 455;
			// #else
			((Activity) this.getContext()).getWindow().getDecorView()
					.getWindowVisibleDisplayFrame(frame);
			int heightVisible = frame.height();
			// #endif
			/**
			 * ----------------------------------------------------------------
			 * 由于存在多个屏幕像素尺寸问题，
			 * 此处通过getWindowVisibleDisplayFrame获得的高度heightVisible是未经过缩放处理的真实像素高度
			 * 这样在非320X480象素的手机上
			 * ，该界面就会存在较大的比例误差。所以此处重新对该高度进行一次初级修正。修正过后的高度只是误差没有那么大，但是
			 * 还是不能达到相当准确的地步
			 */
			DisplayMetrics dm = new DisplayMetrics();
			bv.getWindowManager().getDefaultDisplay().getMetrics(dm);
			float scaledDensity = dm.scaledDensity;
			heightVisible = (int) (heightVisible / scaledDensity);
			/**
			 * ----------------------------------------------------------------
			 */
			// 先减去界面上方自定义的titleBar的高度
			heightVisible = heightVisible - bv.titleBar_.height_;
			// 再减去下方statusbar的高度
			heightVisible = heightVisible - bv.statusBar_.getHeight();
			final int size = bv.tabBar_.getContentLayout().getChildCount();
			Object o = null;
			for (int i = 0; i < size; i++) {
				o = bv.tabBar_.getContentLayout().getChildAt(i);
				if (o instanceof Wrap)
					continue;
				if (o instanceof Div) {
					Div lll = (Div) o;
					heightVisible = heightVisible
							- BaseView.DEFAULT_VIEW_TOP_MARGIN;
					heightVisible = heightVisible - lll.height_;
				}
			}
			heightVisible = heightVisible - (BaseView.DEFAULT_VIEW_TOP_MARGIN << 1);
			if (null == linearLayoutView_) {
				linearLayoutView_ = new LPLinearLayoutView(bv_, height_);
				lop.height = heightVisible;
				linearLayoutView_.sWidth_ = lop.width;
				linearLayoutView_.sHeight_ = lop.height;
				linearLayoutView_.setLayoutParams(lop);
				linearLayoutView_.setShape(drawable_);
				linearLayoutView_.setBackgroundImg(backgroundImg_);
				// 设置一个透明颜色，否则在LPLinearLayoutView里的onDraw方法里无法画出圆角矩形
				linearLayoutView_.setBackgroundColor(0);
				LinearLayout.LayoutParams llltemp = (android.widget.LinearLayout.LayoutParams) this.getLayoutParams();
				if (null == llltemp) {
					llltemp = new LinearLayout.LayoutParams(width_, height_);
				}
				llltemp.width = width_;
				llltemp.height = height_;
				setLayoutParams(llltemp);
				linearLayoutView_.addView(this);
			}
		} else {
			float systemVersion = ConfigManager.SYSTEMVISION;
			if ((systemVersion > 1.5 || !hasTextField_)
					&& ((h < height_ && rows_ > 1) || width_ > w)) {
				if (linearLayoutView_ == null) {
					linearLayoutView_ = new LPLinearLayoutView(bv_, height_);
					linearLayoutView_.setShape(drawable_);
					linearLayoutView_.setBackgroundImg(backgroundImg_);
					linearLayoutView_.setLayoutParams(lop);
					linearLayoutView_.sWidth_ = lop.width;
					linearLayoutView_.sHeight_ = lop.height;
					// 设置一个透明颜色，否则在LPLinearLayoutView里的onDraw方法里无法画出圆角矩形
					linearLayoutView_.setBackgroundColor(0);
					LinearLayout.LayoutParams llltemp = (android.widget.LinearLayout.LayoutParams) this
							.getLayoutParams();
					if (null == llltemp) {
						llltemp = new LinearLayout.LayoutParams(width_, height_);
					}
					llltemp.width = width_;
					llltemp.height = height_;
					setLayoutParams(llltemp);
					linearLayoutView_.addView(this);
				}
			} else {
				if (h < height_) {
					// 服务端有指定表格的高，则还是按服务端指定的高来排列控件，同时根据指定高适当的所见表格的每行高
					this.resetHeightArray(height_, h);
					height_ = h;
				}
				setLayoutParams(lop);
			}
		}
	}

	/**
     * 
     */
	private void setTableBgImg() {
		CssStyle cs = cssStyle_;
		Bitmap bgImg = null;
		if (cs != null && cs.bgImageUrl_ != null) {
			if (cs.bgImageUrl_.startsWith("local:")) {
				String imgName = cs.bgImageUrl_.substring("local:".length());
				if (imgName.equals("divBg.png")) {
					bgImg = ConstantRepository.decodeBitmap(bv_.getResources(),
							R.drawable.divbg);
				}
			}
		}
		// Extends background image.
		if (bgImg != null) {
			int w = width_;
			int h = height_;
			if (cssStyle_ != null && cssStyle_.width_ > 0) {
				w = cssStyle_.width_;
			}
			if (cssStyle_ != null && cssStyle_.height_ > 0) {
				h = cssStyle_.height_;
			}
			backgroundImg_ = Bitmap.createScaledBitmap(bgImg, w, h, true);
			if (!bgImg.isRecycled()) {
				bgImg.recycle();
			}
			bgImg = null;
		}
	}

	/**
	 * Returns true if this table contains the specified element.
	 * 
	 * @param table
	 * @param cmp
	 * @return
	 */
	public static final boolean contains(Table table, Component cmp) {
		boolean b = false;
		Cell findCell = findCell((View) cmp);
		if (findCell != null) {
			return false;
		}
		try {
			for (Cell cell : table.cells_) {
				if (findCell == cell) {
					b = true;
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			Utils.printException(e);
		}
		return b;
	}

	/**
	 * @param table
	 * @return
	 */
	public static String getCurrentAccessory(Table table) {
		return table.accessory_.get(table.currentAccessoryIndex_);
	}

	/**
	 * @param table
	 * @return
	 */
	public static String getCurrentAddendum(Table table) {
		if (!table.addendum_.isEmpty()) {
			return table.addendum_.get(table.currentAccessoryIndex_);
		}
		return null;
	}

	/**
	 * @param table
	 * @param cmp
	 * @return
	 */
	public static ArrayList<Component> findSameRowComponents(Table table,
			Component cmp) {
		Cell findCell = findCell((View) cmp);
		if (findCell == null) {
			return null;
		}

		return findComponentsInRow(table, findCell.r);
	}

	/**
	 * @param table
	 * @param findViews
	 * @param findRow
	 */
	protected static ArrayList<Component> findComponentsInRow(Table table,
			int findRow) {
		if (table == null || findRow < 0 || findRow > table.rows_ - 1) {
			return null;
		}
		ArrayList<Component> findViews = new ArrayList<Component>();
		Cell cell = null;
		for (int i = 0; i < table.cells_.size(); i++) {
			cell = table.cells_.elementAt(i);
			if (cell.r != findRow) {
				continue;
			}
			for (int j = 0; j < cell.size(); j++) {
				// TODO Maybe the component in the cell is a ViewGroup.
				Component c = (Component) cell.elementAt(j);
				if (c != null) {
					findViews.add(c);
				}
			}
		}
		if (findViews.size() < 1) {
			findViews = null;
		}
		return findViews;
	}

	/**
	 * @param table
	 * @param selectKeyStr
	 * @return
	 */
	public static Select findSelect(Table table, String selectKeyStr) {
		if (table == null || selectKeyStr == null || selectKeyStr.equals("")) {
			return null;
		}
		int findRow = table.currentAccessoryIndex_;
		ArrayList<Component> views = Table
				.findComponentsInRow(table, findRow);
		if (views == null) {
			return null;
		}
		Select select = null;
		for (int i = 0; i < views.size(); i++) {
			Component c = views.get(i);
			if (c instanceof Select) {
				select = (Select) c;
				if (select.attrName_.equals(selectKeyStr)) {
					// find the same name Select.
					break;
				} else if (select.attrAccessory_.equals(selectKeyStr)) {
					// find the same accessory Select.
					break;
				}
			}
			select = null;
		}
		return select;
	}

	/**
	 * Create cell from a special string.
	 * 
	 * @param backValue
	 * @param view
	 * @return
	 */
	public static Table.Cell createCell(String backValue, Cell oldCell,
			BaseView baseView, int row, int column) throws Exception {
		if (backValue == null || backValue.equals("") || oldCell == null) {
			return null;
		}
		// create labels
		String[] rowLabel = Utils.string2Array(backValue, "|");
		if (rowLabel == null) {
			return null;
		}
		Table.Cell neoCell = null;
		neoCell = new Table.Cell();
		neoCell.r = row;
		neoCell.c = column;
		// apply cell CSS style.
		// ParseHtml.applyCssOnComponent(neoCell, oldCell.cssStyle_, null);
		neoCell.setCssStyle(oldCell.cssStyle_);
		int index = 0; // index of the old cell.
		for (int i = 0; i < rowLabel.length; i++) {
			if (rowLabel[i] == null) {
				continue;
			}
			if (rowLabel[i].indexOf(',') > -1) {
				// the label must be divided.
				String[] innerTexts = Utils.string2Array(rowLabel[i], ",");
				if (innerTexts == null) {
					continue;
				}
				for (int j = 0; j < innerTexts.length; j++) {
					if (innerTexts[j] == null) {
						continue;
					}
					Label neoLable = new Label(baseView, innerTexts[j],
							false);
					Label oldLable = (Label) oldCell.elementAt(index);
					// ParseHtml
					// .applyCssOnTextView(neoLable, oldLable.cssStyle_);
					// ParseHtml.applyPseudoCssOnLabel(neoLable,
					// oldLable.pseudoStyle_);
					neoLable.setCssStyle(oldLable.cssStyle_);
					neoLable.pseudoStyle_ = oldLable.pseudoStyle_;
					neoCell.add(neoLable);
					index++;
				}
			} else {
				Label neoLable = new Label(baseView, rowLabel[i], false);
				Label oldLable = (Label) oldCell.elementAt(index);
				neoLable.setCssStyle(oldLable.cssStyle_);
				neoLable.pseudoStyle_ = oldLable.pseudoStyle_;
				neoCell.add(neoLable);
				index++;
			}
			neoCell.add(new Wrap());
			index++;
		}
		return neoCell;
	}

	/**
	 * Get all views in this table.
	 * 
	 * @return
	 */
	public ArrayList<Component> getAllViews() {
		ArrayList<Component> views = null;
		try {
			views = new ArrayList<Component>();
			for (Cell cell : cells_) {
				for (Component c : cell.cellItems) {
					views.add(c);
				}
			}
		} catch (Exception e) {
			views = null;
		}
		return views;
	}

	public void setBackgroundColor(int color) {
		// bgColor_ = color;
		drawable_ = null;
		if (cssStyle_ != null && cssStyle_.width_ > MAX_WIDTH) {
			// create Rectangle.
			drawable_ = new ShapeDrawable(new RectShape());
		} else {
			drawable_ = createRoundRect();
		}
		drawable_.getPaint().setColor(color);
	}

	public void cleanText() {
		// TODO Auto-generated method stub

	}

	public String getContentText() {
		// TODO Auto-generated method stub
		return null;
	}

	public void mould() {
		CssStyle cs = cssStyle_;
		if (cs != null && cs.bgColor_ != 0) {
			setBackgroundColor(cs.bgColor_);
		}

		if (cs != null && cs.borderWidth_ > 0) {
			hasBorder_ = true;
		}
		// 防止table控件多次调用mould方法加载子元素问题
		BaseView.removeViewsStepByStep(this, null);
		reLayoutTable();

		super.setBackgroundColor(0);
	}

	public void setContentText(String text) {
		// TODO Auto-generated method stub

	}

	public void shrinkWidth() {
		// TODO Auto-generated method stub

	}

	private final static ShapeDrawable createRoundRect() {
		float[] outerRoundRect = new float[8];
		for (int i = 0; i < 8; i++) {
			outerRoundRect[i] = CORNER_RADIUS;
		}
		return new ShapeDrawable(new RoundRectShape(outerRoundRect, null, null));
	}

	protected void onDraw(Canvas canvas) {
		if (linearLayoutView_ == null) {
			drawTableBg(canvas);
		}
		drawRowBg(canvas);
		if (isDrawRowBg_) {
			drawTouchRowBg(canvas);
		}
		super.onDraw(canvas);
		drawBorder(canvas);
		drawArrow(canvas);

		if (tableTimer_ == null && updateUrl_ != null && updateTime_ != null) {
			// BaseView.wantToUpdateTable_ = "1";
			newTimerToUpdateThisTable();
		}
	}

	/**
	 * @param canvas
	 */
	private void drawTableBg(Canvas canvas) {
		if (drawable_ != null) {
			int w = width_;

			int h = height_;
			ViewGroup.LayoutParams lp = null;
			if (linearLayoutView_ != null) {
				lp = linearLayoutView_.getLayoutParams();
			} else {
				lp = getLayoutParams();
			}

			if (lp != null) {
				w = Math.max(w, lp.width);
				h = Math.max(h, lp.height);
			}
			if (w == 303 && iscontain_) {
				drawable_.setBounds(3, 0, w - 3, h);
			} else {
				drawable_.setBounds(0, 0, w, h);
			}
			drawable_.draw(canvas);
		}

		if (backgroundImg_ != null) {
			canvas.drawBitmap(backgroundImg_, 0, 0, tablePaint_);
		}
	}

	private void drawRowBg(Canvas canvas) {
		int size = 0;
		if (rowStyle != null) {
			size = rowStyle.size();
		}
		int y = PADDING_VERTICAL;
		for (int i = 0; i < size; i++) {
			CssStyle cs = rowStyle.get(i);
			if (cs == null || cs.bgColor_ == 0) {
				continue;
			}
			tablePaint_.setColor(cs.bgColor_);
			tablePaint_.setStyle(Style.FILL);
			canvas.drawRect(PADDING_HORIZONAL, y, width_ - PADDING_HORIZONAL, y
					+ maxHeightRow_[i], tablePaint_);
			y += maxHeightRow_[i];
		}

	}

	/**
	 * @param canvas
	 */
	private void drawArrow(Canvas canvas) {
		int h = TABLEARR.getHeight();
		float y = PADDING_VERTICAL - h / 2;
		for (int i = 0; i < accessory_.size(); i++) {
			if (null != maxHeightRow_) {
				y += (maxHeightRow_[i] / 2.0);
				String s = accessory_.get(i);
				if (s != null) {
					canvas.drawBitmap(TABLEARR, (Utils.screenWidth_ - Utils.getScaledValue(10) - 20), y, tablePaint_);
				}
				y += (maxHeightRow_[i] / 2.0);
			}
		}
	}

	/**
	 * Draw the background of the current touched row.
	 * 
	 * @param canvas
	 */
	private void drawTouchRowBg(Canvas canvas) {
		try {
			// Don't draw the row touching background if the row has no
			// accessory.
			if (accessory_.get(currentAccessoryIndex_) == null) {
				return;
			}
			int y = PADDING_VERTICAL;
			for (int i = 0; i < currentAccessoryIndex_; i++) {
				y += maxHeightRow_[i];
			}
			tablePaint_.setColor(ROW_TOUCH_BG_COLOR);
			canvas.drawRect(PADDING_HORIZONAL, y, width_ - PADDING_HORIZONAL, y
					+ maxHeightRow_[currentAccessoryIndex_], tablePaint_);
		} catch (Exception e) {
		}
	}

	/**
	 * @param canvas
	 * @return
	 */
	private void drawBorder(Canvas canvas) {
		// draw cell borders.
		int y = PADDING_VERTICAL;
		tablePaint_.setColor(INNER_BORDER_COLOR);
		for (int i = 1; i < rows_; i++) {
			y += maxHeightRow_[i - 1];
			canvas.drawLine(PADDING_HORIZONAL + CORNER_RADIUS, y, width_
					- PADDING_HORIZONAL - CORNER_RADIUS, y, tablePaint_);
		}
		// draw ceiling and floor borders of this table.
		if (cssStyle_ == null || cssStyle_.borderColors_ == null) {
			return;
		}
		// draw the floor border of this table.
		int bottomBorderColor = cssStyle_.borderColors_[CssStyle.BORDER_BOTTOM];
		if (bottomBorderColor != 0) {
			tablePaint_.setColor(bottomBorderColor);
			int x1 = PADDING_HORIZONAL + CORNER_RADIUS;
			int x2 = width_ - PADDING_HORIZONAL - CORNER_RADIUS;
			int y1 = height_ - PADDING_VERTICAL + 1;
			canvas.drawLine(x1, y1, x2, y1, tablePaint_);
		}
		// draw the ceiling border of this table.
		int topBorderColor = cssStyle_.borderColors_[CssStyle.BORDER_TOP];
		if (topBorderColor != 0) {
			tablePaint_.setColor(topBorderColor);
			int x1 = PADDING_HORIZONAL + CORNER_RADIUS;
			int x2 = width_ - PADDING_HORIZONAL - CORNER_RADIUS;
			int y1 = PADDING_VERTICAL + 1;
			canvas.drawLine(x1, y1, x2, y1, tablePaint_);
		}

	}

	public boolean onTouchEvent(MotionEvent event) {
		int touchEvent = event.getAction();
		int x = (int) event.getX();
		int y = (int) event.getY();
		try {
			int index = getCurrentRow(event.getX(), event.getY());
			switch (touchEvent) {
			case MotionEvent.ACTION_DOWN:
				downX_ = (int) event.getX();
				downY_ = (int) event.getY();
				tScrollX_ = thisTable_.getScrollX();
				tScrollY_ = thisTable_.getScrollY();
				laytHeight_ = (thisTable_.getLayoutParams()).height;

				setCurrentTouchRow(index);
				isDrawRowBg_ = true;
				invalidate();
				break;
			case MotionEvent.ACTION_MOVE:
				if (Math.abs(x - downX_) > Utils.getScaledValue(5)
						|| Math.abs(y - downY_) > Utils.getScaledValue(5)) {
					isDrawRowBg_ = false;
					invalidate();
				}
				break;
			case MotionEvent.ACTION_UP:
				systemTime_ = System.currentTimeMillis() - systemTime_;
				setCurrentTouchRow(index);
				if (systemTime_ > 1000
						&& Math.abs(x - downX_) < Utils.getScaledValue(5)
						&& Math.abs(y - downY_) < Utils.getScaledValue(5)) {
					// 拖動距離大於等於5則不響應彈起操作
					tablePressed();
				}
				isDrawRowBg_ = false;
				invalidate();
				break;
			default:
				isDrawRowBg_ = false;
				invalidate();
				return super.onTouchEvent(event);
			}

		} catch (Exception e) {
			Utils.printException(e);
		}
		return true;
	}

	private int getCurrentRow(float x, float y) {
		int index = -1;
		int startY = PADDING_VERTICAL;
		for (int i = 0; i < maxHeightRow_.length; i++) {
			if (y >= startY && y <= startY + maxHeightRow_[i]) {
				if (x > PADDING_HORIZONAL && x < width_ - PADDING_HORIZONAL) {
					index = i;
				}
				break;
			}
			startY += maxHeightRow_[i];
		}
		return index;
	}

	/**
	 * @param cell
	 * @throws Exception
	 */
	private void tablePressed() throws Exception {
		BaseView bv = (BaseView) this.getContext();
		if (listener_ != null) {
			listener_.componentAction(this, bv);
		} else if (bv_ != null && bv_.listener_ != null) {
			bv_.listener_.componentAction(this, bv);
		}
	}

	/**
	 * @param cell
	 */
	private void setCurrentTouchRow(Cell cell) {
		setCurrentCell(cell);
		currentAccessoryIndex_ = -1;
		if (cell == null) {
			return;
		}
		currentAccessoryIndex_ = cell.r;
	}

	public Cell getCurrentCell() {
		return currentCell_;
	}

	public void setCurrentCell(Cell currentCell) {
		this.currentCell_ = currentCell;
	}

	/**
	 * @param index
	 */
	private void setCurrentTouchRow(int index) {
		System.out.println("******************index==" + index);
		currentAccessoryIndex_ = index;
	}

	public void setCmpHeidht(int height) {
		// TODO Auto-generated method stub

	}

	public void setCmpWidth(int width) {
		// TODO Auto-generated method stub

	}

	public void setCssStyle(CssStyle style) {
		cssStyle_ = style;
	}

	/**
	 * @param style
	 */
	public void addRowStyle(CssStyle style) {
		if (rowStyle == null) {
			rowStyle = new ArrayList<CssStyle>();
		}
		rowStyle.add(style);
	}

	public void copyAttribute(Table parentTable) {
		if (parentTable == null) {
			return;
		}
		attrName_ = parentTable.attrName_;
	}

	public View getCmpView() {
		if (linearLayoutView_ != null) {
			return linearLayoutView_;
		} else {
			return this;
		}
	}

	public void addChild(Component cmp) {
		// TODO Auto-generated method stub

	}

	public Component child(int index) {
		// TODO Auto-generated method stub
		return null;
	}

	public int childrenAmount() {
		// TODO Auto-generated method stub
		return 0;
	}

	public void loadAllChildren() {
		// TODO Auto-generated method stub

	}

	/**
	 * Find the table includes the component.
	 * 
	 * @param view
	 * @return
	 */
	public static final Table findTable(View view) {
		Table table = null;
		try {
			ViewParent parent = view.getParent();
			if (!(parent instanceof ViewGroup)) {
				return null;
			}
			if (parent instanceof Table) {
				table = (Table) parent;
			} else {
				table = findTable((View) parent);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			Utils.printException(e);
		}
		return table;
	}

	public static final Cell findCell(View view) {
		Cell cell = null;
		try {
			ViewParent parent = view.getParent();
			if (!(parent instanceof ViewGroup)) {
				return null;
			}
			if (parent instanceof Cell.CellLayout) {
				cell = ((Cell.CellLayout) parent).cell_;
			} else {
				cell = findCell((View) parent);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			Utils.printException(e);
		}
		return cell;
	}

	public void removeChild(Component cmp) {
		// TODO Auto-generated method stub

	}

	public int getCmpHeight() {
		return height_;
	}

	public int getCmpWidth() {
		return width_;
	}

	public void setInTable(boolean inTable) {
		// TODO Auto-generated method stub

	}

	public boolean isInTable() {
		// TODO Auto-generated method stub
		return false;
	}

	public CssStyle getCssStyle() {
		// TODO Auto-generated method stub
		return null;
	}

	public void releaseResource(View view) {
		// TODO Auto-generated method stub
		// cssStyle_ = null;
		// attrName_ = null;
		// maxWidthCol_ = null;
		// maxHeightRow_ = null;
		// copyMaxHeightRow_ = null;
		// timePriceSort = null;
		// sortTime.clear();
		// sortTime = null;
		// sortPrice.clear();
		// sortPrice = null;
		// cells_.clear();
		// cells_ = null;
		// tablePaint_ = null;
		// accessory_.clear();
		// accessory_ = null;
		// drawable_ = null;
		// rowStyle.clear();
		// rowStyle = null;
		// linearLayoutView_ = null;

		if (null != backgroundImg_ && !backgroundImg_.isRecycled())
			backgroundImg_.recycle();
		backgroundImg_ = null;

		Utils.releaseResource(view);
	}

	public void setForm(FormLayout formLayout) {
		// TODO Auto-generated method stub
		formLayout_ = formLayout;
	}

	public FormLayout getForm() {
		// TODO Auto-generated method stub
		return formLayout_;
	}

	@Override
	public void setEncrypt(String encrypt) {
		// TODO Auto-generated method stub

	}

	/**
	 * 只更新本table
	 * */
	public void newTimerToUpdateThisTable() {
		String url = "http" + updateUrl_.substring(2);
		System.out.println("*************url=====" + url);
		String body = null;
		int index = url.indexOf("?");
		if (index != -1) {
			body = url.substring(index + 1);
			url = url.substring(0, index);
		}
		final String fUrl = url;
		final String fBody = body;

		tableTimer_ = new Timer();
		long updateTime = Integer.parseInt(updateTime_) * 1000;
		BaseView.ttimerIscannel_ = false;

		tableTimer_.schedule(new TimerTask() {
			public void run() {
				if (!BaseView.ttimerIscannel_ && !BaseView.timerIsRunning_
						&& BaseView.wantToUpdateTable_.equals("1")) {
					BaseView.timerIsRunning_ = true;
					BaseView.mid_.channelEntity_.loadUpdateTable(fUrl,
							fBody, bv_);
				}
			}
		}, updateTime, updateTime);

	}

}
